# https://blog.csdn.net/m0_37242314/article/details/148592449
checkpoint_data = {
    "thread_id": "bug123",
    "thread_ts": "2025-06-11T07:23:38.656547+00:00",
    "checkpoint": {
        "id": "1ef968fe-1eb4-6049-bfff",
    },
    "metadata": {"timestamp": "2025-06-11T07:23:38.656547+00:00"}
}

import sqlite3
from langgraph.checkpoint.sqlite import SqliteSaver
#
with SqliteSaver.from_conn_string("checkpoints20250611.sqlite") as memory:

    # 检索检查点的数据
    config = {"configurable": {"thread_id": checkpoint_data["thread_id"]}}

    # 获取给定 thread_id 的所有检查点
    checkpoints = list(memory.list(config))
    for checkpoint in checkpoints:
        print(checkpoint)
# 运行结果
# CheckpointTuple(
#     config={'configurable': {'thread_id': 'bug123', 'checkpoint_ns': '', 'checkpoint_id': '1ef968fe-1eb4-6049-bfff'}},
#     checkpoint={'id': '1ef968fe-1eb4-6049-bfff'},
#     metadata={'timestamp': '2025-06-11T07:23:38.656547+00:00', 'thread_id': 'bug123',
#               'thread_ts': '2025-06-11T07:23:38.656547+00:00'}, parent_config=None, pending_writes=[])


# 建立数据库连接
conn = sqlite3.connect("checkpoints20250611.sqlite")

# 创建一个游标对象来执行你的SQL查询
cursor = conn.cursor()

# 查询数据库中所有表的名称
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")

# 获取查询结果
tables = cursor.fetchall()
# 打印所有表名
for table in tables:
    print(table)
# 从检查点表中检索所有数据
cursor.execute(f"SELECT * FROM checkpoints;")
all_data = cursor.fetchall()

# 打印检查点表中的所有数据
print("Data in the 'checkpoints' table:")
for row in all_data:
    print(row)
